package Test;

import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TCPClient {

    public static void main(String[] args) {

        Socket client = null;
        try {
            // 创建一个客户端连接到指定的服务器端     发送请求 --- 第一次握手
            client = new Socket(InetAddress.getLocalHost(),7788);

            // 获取服务器端返回的输入流数据并打印
            InputStream is = client.getInputStream();
            byte[] buf = new byte[1024];
            int len = 0 ;
            while ((len = is.read(buf))!=-1){
                System.out.println(new String(buf,0,len));
                is.read(buf);
            }

            // 关闭流和连接
            is.close();
            client.close();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

}
